<?php

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/8/29
 * Time: 14:33
 */
class EmailModel
{
    /**
     * 发送邮件
     * @param array $receiverIdArr  邮件通知的成员
     * @param array $task  发送的邮件内容
     */
    public function sendEmail($receiverIdArr,$task){
        $ids = My::implode(',', $receiverIdArr);
        if(!My::is_ids($ids)) return false;
        $email_ressult = DB('homeuser')->where("id IN({$ids})")->field('email')->cache()->select();
        if(!$email_ressult)
            return false;
        $receiver = array();

        $task_link = "http://".$_SERVER ['HTTP_HOST'].__PROJECT__."Myproject/teacher_detail/id-".$task['id']."/";
        foreach ($email_ressult as $key => $value)
            $receiver[] = $value['email'];
        $content =   $task['project'].
            "<br/>时间：".date("Y年m月d日 H:i:s").
            "<br/>状态：".$task['result'].
            "<br/>发送方：".$task['type'].
            "<br/><a href='".$task_link."' target='_blank'>点击前往</a>";
        //获取发件人的信息
        $result = My::alias2detail('config','system_mail');
        if(is_array($result)){
            $param['username'] = $result['params']['email_username'];
            $param['password'] = $result['params']['email_password'];
            $param['host'] = $result['params']['email_host'];
            $param['fromname'] = $result['params']['email_fromname'];
        }
        $param['receiver'] = $receiver;
        $param['title'] = '项目信息';
        $param['content'] = $content;
        $ok = My::sendMail($param);
        return $ok;
    }
}